/*
 * ParameterStore.cpp
 *
 *  Created on: Jul 17, 2016
 *      Author: Yang
 */

#include "ParameterStore.hpp"

Parameter_Store Parameter;

void Parameter_Store::init(void)
{
    uint8_t flag = 0;
    len = sizeof(data);
    fe24CXX.init();
    flag = fe24CXX.ReadOneByte(INITIALIZED_FLASH);
    if (flag == INITIALIZED_FLAG)
    {
        load();
        console.printf((char*) "Fe RAM Parameter has initialized                [JUMP]\r\n");
    }
    else
    {
        fe24CXX.WriteOneByte(INITIALIZED_FLASH, INITIALIZED_FLAG);

        data.Compass_Calibrate_Flag = 0;
        data.Compass_X_Offset = 0;
        data.Compass_Y_Offset = 0;
        data.Compass_Z_Offset = 0;
        data.Compass_X_Mul = 1;
        data.Compass_Y_Mul = 1;
        data.Compass_Z_Mul = 1;

        write();
        console.printf((char*) "Fe RAM Parameter Initialize                       [OK]\r\n");
    }
}

void Parameter_Store::load(void)
{
    fe24CXX.Read(COMPASS_CALIBRATION, (uint8_t*) &data, len);
}
void Parameter_Store::write(void)
{
    fe24CXX.Write(COMPASS_CALIBRATION, (uint8_t*) &data, len);
}

void Parameter_Store_init(void)
{
    Parameter.init();
}

